import java.io.*;
import java.util.*;

import javax.media.opengl.GL;
import javax.media.opengl.glu.GLU;

/**
 * @author Eric Muehlberg
 *
 */
public class Map
{

	ArrayList<WObject> mapobjects;
	WObject start;
	String nextLevel;
	int ctext;
	int width, height;
	
	public Map(String filename, GL gl) throws IOException
	{
		mapobjects = new ArrayList<WObject>();
		mapobjects.clear();
		this.width = width;
		this.height = height;
		
		//Generate Map from file
		
		if(filename == null)
		{
			System.exit(0);
		}
		
		BufferedReader r = new BufferedReader(new FileReader(filename));
		StringTokenizer s;
		while(r.ready())
		{
			s = new StringTokenizer(r.readLine());
			/*if(s.toString().contains("//"))
				continue;*/
			
			while(s.hasMoreTokens())
			{
				String str = s.nextToken();
				if(str.equals("cube"))
				{
					int x = Integer.parseInt(s.nextToken());
					int y = Integer.parseInt(s.nextToken());
					int z = Integer.parseInt(s.nextToken());
					int w = Integer.parseInt(s.nextToken());
					int h = Integer.parseInt(s.nextToken());
					int d = Integer.parseInt(s.nextToken());

					String modelfile = s.nextToken().toString();					
					mapobjects.add(new ObjectThree(x,y,z,w,h,d,str,modelfile, true));
				}
				//level end beacon
				else if(str.equals("end"))
				{
					int x = Integer.parseInt(s.nextToken());
					int y = Integer.parseInt(s.nextToken());
					int z = Integer.parseInt(s.nextToken());
					int w = Integer.parseInt(s.nextToken());
					int h = Integer.parseInt(s.nextToken());
					int d = Integer.parseInt(s.nextToken());

					String modelfile = s.nextToken().toString();					
					mapobjects.add(new ObjectThree(x,y,z,w,h,d,str,modelfile, true));
					String next = s.nextToken().toString();
					if(!next.equals("null"))
						nextLevel = next;
					else
						nextLevel = null;
				}
				//level start beacon
				else if(str.equals("start"))
				{
					int x = Integer.parseInt(s.nextToken());
					int y = Integer.parseInt(s.nextToken());
					int z = Integer.parseInt(s.nextToken());
					int w = Integer.parseInt(s.nextToken());
					int h = Integer.parseInt(s.nextToken());
					int d = Integer.parseInt(s.nextToken());

					String modelfile = s.nextToken().toString();					
					//mapobjects.add(new ObjectThree(x,y,z,w,h,d,str,null,false));
					start = new ObjectThree(x,y,z,w,h,d,str,null,false);
				}
				//Bottom of level
				else if(str.equals("bottom"))
				{
					int x = Integer.parseInt(s.nextToken());
					int y = Integer.parseInt(s.nextToken());
					int z = Integer.parseInt(s.nextToken());
					int w = Integer.parseInt(s.nextToken());
					int h = Integer.parseInt(s.nextToken());
					int d = Integer.parseInt(s.nextToken());

					String modelfile = s.nextToken().toString();					
					mapobjects.add(new ObjectThree(x,y,z,w,h,d,str,null,true));
				}
				//Texture
				else if(str.equals("texture"))
				{
					String file = s.nextToken().toString();
					int[] temp = new int[1];
					gl.glGenTextures(1, temp, 0);
					gl.glBindTexture(GL.GL_TEXTURE_2D, ctext);
				}
				
			}
		}
		
		
	}
	
}
